package com.along.htybrowser.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Switch;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.along.htybrowser.R;
import com.along.htybrowser.bean.ResourcesBean;

import java.util.ArrayList;

/**
 * @author wen66to88@163.com
 * @date 2021/7/9 - 15:22
 */
public class ResAdapter extends RecyclerView.Adapter<ResAdapter.ViewHolder> {
    private ArrayList<ResourcesBean> beanList;

    public ResAdapter(ArrayList<ResourcesBean> beanList) {
        this.beanList = beanList;
    }

    @NonNull
    @Override
    public ResAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.adapter_res_show, parent, false);
        return new ResAdapter.ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ResAdapter.ViewHolder holder, int position) {
        ResourcesBean bean = beanList.get(position);
        holder.resUrlTv.setText(bean.getUrl());
        holder.interceptSwitch.setChecked(bean.isIntercept());
        holder.interceptSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> {
            if (isChecked) {

            } else {

            }
        });
    }

    @Override
    public int getItemCount() {
        return beanList == null ? 0 : beanList.size();
    }

    class ViewHolder extends RecyclerView.ViewHolder {
        TextView resUrlTv;
        Switch interceptSwitch;

        public ViewHolder(View view) {
            super(view);
            resUrlTv = view.findViewById(R.id.res_url_tv);
            interceptSwitch = view.findViewById(R.id.intercept_switch);
        }
    }
}